﻿Imports SharedCode.PublicEnums
Imports System.Configuration.ConfigurationSettings
Imports System.Xml
Imports System.Windows.Forms
Public Class ConfigurationFile
    Public Sub ConfigurationFileReader()

    End Sub
    Public Sub ConfigurationFileAddConnection(ByVal ConnectionName As String, ByVal SourceConnectionType As QueueTypes, ByVal SourceServer As String, ByVal SourceQueue As String, ByVal DestinationConnectionType As QueueTypes, ByVal DestinationServer As String, ByVal DestinationQueue As String)
        Dim xmlDocument As New XmlDocument
        Dim xmlNode As XmlNode
        Dim xmlRoot As XmlNode
        Dim xmlKey As XmlNode
        Dim xmlValue As XmlNode

        xmlDocument.Load(Application.ExecutablePath + ".config")
        xmlNode = xmlDocument.DocumentElement.SelectSingleNode("/configuration/appSettings/add[@key=""" & ConnectionName & """]")
        If xmlNode Is Nothing Then
            'Add the node
            xmlNode = xmlDocument.CreateNode(XmlNodeType.Element, "ad", "")
            'Adding the Key attribute of the node
            xmlKey = xmlDocument.CreateNode(XmlNodeType.Attribute, "key", "")
            xmlKey.Value = ConnectionName
            xmlNode.Attributes.SetNamedItem(xmlKey)

            xmlValue = xmlDocument.CreateNode(XmlNodeType.Attribute, "sourceconnectiontype", "")
            xmlValue.Value = SourceConnectionType

            xmlRoot = xmlDocument.DocumentElement.SelectSingleNode("/configuration/appSettings")
            If Not xmlRoot Is Nothing Then
                xmlRoot.AppendChild(xmlNode)
            Else
                MsgBox("Error Writing to Configuration File.  Your changes were not saved.")
            End If
        Else
            xmlNode.Attributes.GetNamedItem("value").Value = ConnectionName
        End If
        xmlDocument.Save(Application.ExecutablePath & ".config")
        xmlDocument = Nothing

    End Sub
    Public Sub ConfigurationFileDeleteConnection(ByVal SourceServer As String, ByVal SourceQueue As String, ByVal DestinationServer As String, ByVal DestinationQueue As String)

    End Sub
    Public Sub ConfigurationFileAdd_ServiceBroker()

    End Sub
End Class
